import React, {Component, PropTypes} from 'react'
import ContactItem from './'

class ContactList extends React.Component {
  render() {
    const filteredContacts = this.props.contacts.filter(
      (contact) => contact.name.indexOf(this.props.filterText) !== -1
    )
    console.log(filteredContacts, '--fitler')
    return (
      <ul>
        {filteredContacts.map(
          (contact) => <ContactItem key={contact.email}
                                    name={contact.name}
                                    email={contact.email} />
        )}
       </ul>
    )
  }
}
ContactList.propTypes = {
  contacts: PropTypes.arrayOf(React.PropTypes.object),
  filterText: PropTypes.string.isRequired,
}


export default ContactList